{% from "macros/forms.html" import form_input %}
{% from "macros/datatable.html" import datatable %}
{% from "macros/variables.html" import tlp_levels %}

{% set columns = [{'title': 'name', 'field': 'name', 'sortable': True, 'searchable': True, 'renderer': None}, {'title': 'description', 'field': 'description', 'sortable': False, 'searchable': False, 'renderer': None}] %}

{% set form_error = form_error | default({}) %}
{% set permissions = permissions | default([]) | tojson %}
<div class="bg-base-100 p-4">
  <h1 class="text-3xl font-bold mb-5 w-3/4 ml-[10%]">{{ submit_text }}</h1>
  <p class="text-base-content/60 text-[0.7rem] mb-5 w-1/2 ml-[10%]">ID: {{ role.id }}</p>
  <form id="role-form" class="w-3/4 ml-[10%]" {{ form_action }} hx-swap="innerHTML"  hx-target="#form-container" hx-target-error="#form-container">
    {% include "partials/admin_form_error.html" %}
    {{ form_input('Name', 'name', role.name, form_error.name) }}
    {{ form_input('Description', 'description', role.description, form_error.description) }}
    {{ tlp_levels(role.tlp_level) }}

    {{ datatable('Permissions', permissions, columns, role.permissions, selectable=true, input_name="permissions[]", headline="Permissions") }}

    <input type="submit" class="btn btn-primary w-3/4" value="{{ submit_text }}" />
  </form>
</div>
